import {
  get
} from "../../untils/db"

Page({
  data: {
    dialogShow: false,
    buttons: [{
      text: '取消'
    }, {
      text: '确定'
    }],
    users: "",
    rows: "",
    status: false,
    num: 0,
    taskMembers: []
  },
  async onLoad() {
    this.setData({
      users: wx.getStorageSync('users')
    })
    let token = wx.getStorageSync('login')
    console.log(this.data.users.deptId);
    let res = await get("/api/employee/members", {
      deptId: this.data.users.deptId
    }, token)
    console.log(res.data.rows);
    this.setData({
      rows: res.data.rows
    })
  },
  h() {
    this.setData({
      dialogShow: true
    })
  },
  tapDialogButton(e) {
    console.log(e.detail);
    if (e.detail.index == 1) {
      wx.navigateTo({
        url: '../zguye/zhuye',
      })
    }
    this.setData({
      dialogShow: false
    })
  },

  change(e) {
    let arr=[]
    this.data.rows.forEach((item)=>{
    arr.push(item.userId)
    })
    if (e.detail.value.length != 0) {
      this.setData({
        status: true,
        num: this.data.rows.length,
        taskMembers:arr
      },()=>{
        console.log(this.data.taskMembers);
      })
    } else {
      this.setData({
        status: false,
        num: 0,
        taskMembers:[]
      },()=>{
        console.log(this.data.taskMembers);
      })
    }
  },

  have(e) {
    this.setData({
      num: e.detail.value.length,
      taskMembers: e.detail.value
    },()=>{
      console.log(this.data.taskMembers);
    })
  },

  truer() {
    if(this.data.taskMembers.length==0){
      wx.showToast({
        title: '请先选择人员',
        icon:"none"
      })
    }else{
      // let string=this.data.taskMembers.join(",")

      wx.setStorageSync('release2', this.data.taskMembers)
      wx.redirectTo({
      url: '../../renwu/zguye/zhuye'
    })
    }
    
  }
})